package com.hqbzl.c1;

import lombok.extern.slf4j.Slf4j;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

@Slf4j
public class TestWait {
    public static void main(String[] args) {
        final Object object = new Object();
        final Thread thread = new Thread(() -> {
            while (true) {
                synchronized (object) {
                    object.notify();
                    log.debug("while notify next");
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "t1");
        thread.start();
        while (true) {
            synchronized (object) {
                try {
                    object.wait();
                    log.debug("while wait next");
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("1");
            }
        }

    }
}
